from flask import jsonify
from backend.utils import json_to_dataframe, read_json_file


def get_scatterplot_data_api(app):
    @app.route('/api/sampling/data')
    def get_scatterplot_data():
        input_file = '../output.json'
        json_data = read_json_file(input_file)
        df = json_to_dataframe(json_data)
        random_df = df.sample(n=10, random_state=None)
        data = random_df[['rating_num', 'movie_name']].to_dict(orient='records')
        return jsonify(data)
